import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.UnsupportedEncodingException;
import java.util.LinkedList;
import java.util.List;
import java.util.Scanner;


public class Main {

	
	
	public static void main(String[] args) {
		Table table= new Table(1);
		Scanner scan = new Scanner(System.in);
		int gameCardsCount= table.getShoes().size()%2;
		System.out.println(table.getShoes());
		do {	
			System.out.println("enter boxes count");
			String str = scan.next();
			int boxCount=Integer.parseInt(str);
			table.deal(boxCount);
			consolePrint(table);
			for (int i=1; i<=boxCount; i++) {
				do {
					System.out.println("make your decision");
					str = scan.next();
					if (str.equals("hit")&&(table.getBox().get(i-1).getScore()<21)) {
						table.getBox().get(i-1).hit(table.getShoes().get(0));
						table.getShoes().remove(0);
					}
					if (table.getBox().get(i-1).getScore()>=21) {
						str="stand";
					}
					consolePrint(table);
				} while (!str.equals("stand"));
			}
			boolean boxesInGame=false;
			for (int i=1; i<=boxCount; i++) {
				if (!table.getBox().get(i-1).isBurned()) {
					boxesInGame=true;
				}
			}
			if (boxesInGame) {
				do {
					table.getDealerCard().setDealerCards(table.getShoes().get(0));
					table.getShoes().remove(0);
				} while (table.getDealerCard().getScore()<17);
				if (table.getDealerCard().getScore()>21) {
					table.getDealerCard().setBurned(true);
				}
			}
			if (!table.getDealerCard().isBurned()) {
				for (int i=1; i<=boxCount; i++) {
					table.getBox().get(i-1).setGameResult(table.getDealerCard().getScore());
				}
			} else {
				for (int i=0; i<=boxCount-1; i++) {
					table.getBox().get(i).setGameResult(0);
				}
			}
			consolePrint(table);
		} while (table.getShoes().size()>=gameCardsCount);
		
		
		
		consolePrint(table);
		System.out.println();
	System.out.println(table.getDealerCard());

	/*	  do {
		   

		   System.out.println("your string:" + str);
		  } while (!scan.hasNext("exit"));
		  scan.close(); */
		
	}

	public static void consolePrint(Table table) {
		System.out.println("----------");
		for (int i=0; i<table.getBoxCount(); i++) {
			System.out.println("box #"+String.valueOf(i+1)+" : "+table.getBox().get(i)+" "+table.getBox().get(i).getGameResult());
		}
		System.out.println("dealer box : "+table.getDealerCard());
	}

}
